<template>
    <div>
        <el-dialog v-model="ViewdialogVisible" width="80%" align-center destroy-on-close draggable>
            <template #header="{ close }">
                <div class="dialog-header flex justify-between items-center">
                    <div>申报材料查看</div>
                    <el-icon class="el-icon--left cursor-pointer" @click="close">
                        <CircleCloseFilled color="#fff" />
                    </el-icon>
                </div>
            </template>
            <div>
                <!-- 基本信息 -->
                <div class="bg-white mt-[10px]">
                    <div class="px-[5px]  text-right" v-if="procInsId != null">
                        <el-link type="primary" @click="checkHistoryModalVisible = true">审核记录</el-link>
                    </div>
                    <BaseHead>基本信息</BaseHead>
                    <div class="p-[10px]">
                        <el-descriptions title="" :column="2" border label-width="140">
                            <el-descriptions-item label-class-name="gdlable" label="奖励名称">{{
            ruleForm.honorName
        }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="奖励级别">{{
                formatHonorLevelId(ruleForm.honorLevel)
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="成果名称">{{
                ruleForm.productName
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="所属单位">{{
                formatUnitId(ruleForm.unitId)
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="申请日期">{{
                ruleForm.applyDate
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="学科名称">
                                <Feedback :id="ruleForm.subjectId" :list="kjxkflList" :mapping="['id', 'label']">
                                </Feedback>
                            </el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="完成单位">{{
            ruleForm.completeUnit
        }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="成果形式">{{
                ruleForm.productMode
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="申请书附件">
                                <div v-for="item in ruleForm.fileList" :key="item.id">{{ item.fileName
                                    }}<el-link type="primary" style="margin-left: 8px;"
                                        @click="downloadMet(item.id)">下载</el-link>
                                </div>
                            </el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="备注">{{
            ruleForm.note
        }}</el-descriptions-item>
                        </el-descriptions>
                    </div>
                </div>
                <!-- 完成人信息 -->
                <div class="bg-white mt-[10px]">
                    <BaseHead>完成人信息 </BaseHead>
                    <div class="p-[10px]">
                        <el-table :data="tableData" border style="width: 100%">
                            <el-table-column align="center" type="index" label="署名顺序" width="80" />
                            <el-table-column align="center" prop="authorType" label="完成人类型">
                                <template #default="scope">
                                    {{
            scope.row.authorType == '1' ? '教师' : scope.row.authorType == '2' ? '学生' : '校外'
        }}</template>
                            </el-table-column>
                            <el-table-column align="center" prop="authorName" label="完成人姓名">

                            </el-table-column>
                            <el-table-column align="center" prop="address" label="性别">
                                <template #default="scope">
                                    {{ scope.row.sexId == '1' ? '男' : scope.row.sexId == '0' ? '女' : '' }}
                                </template>
                            </el-table-column>
                            <el-table-column align="center" prop="eduLevelId" label="学历">
                                <template #default="scope">
                                    {{
            formateduLevelId(scope.row.eduLevelId)
                                    }}</template>
                            </el-table-column>
                            <el-table-column align="center" prop="authorUnit" label="工作单位">
                                <template #default="scope">
                                    <span v-if="scope.row.authorType == 3">{{scope.row.authorUnit }}</span>
                                    <Feedback v-else :id="scope.row.authorUnitId" :list="sydwList"
                                        :mapping="['codeColumn', 'valueColumn']">
                                    </Feedback>
                                </template>
                            </el-table-column>
                            <el-table-column align="center" prop="titleId" label="职称">
                                <template #default="scope">
                                    <el-tree-select v-model="scope.row.titleId" node-key="id" :data="zcList"
                                        :render-after-expand="false" disabled />
                                </template>
                            </el-table-column>
                            <el-table-column align="center" prop="workRatio" label="贡献率（%）">
                            </el-table-column>
                        </el-table>
                    </div>
                </div>
            </div>
        </el-dialog>
    </div>
    <CheckHistoryModal v-model="checkHistoryModalVisible" :procInsId="procInsId" :checker="checker"
        :checkDate="checkDate" />
</template>
<script setup>
import BaseHead from "@/views/project/components/BaseHead.vue";
import CheckHistoryModal from "@/views/project/components/CheckHistoryModal.vue";

const ViewdialogVisible = defineModel();
const props = defineProps({
    hjztList: Array,
    hjjbList: Array,
    zcgsdwList: Array,
    kjxkflList: Array,
    xlList: Array,
    zcList: Array,
    sydwList: Array,
})

const checkHistoryModalVisible = ref(false);
const procInsId = ref(null); //流程实例id
const checker = ref("");
const checkDate = ref("");

const ruleForm = reactive({
    name: '',
    applyInfoId: '',
    honorName: '',
    honorLevel: '',
    productName: '',
    unitId: '',
    subjectId: '',
    completeUnit: '',
    productMode: '',
    note: '',
});
const tableData = reactive([
]);

const formatHonorLevelId = (cellValue) => {
    if (props.hjjbList.length && cellValue) {
        return props.hjjbList.find(item => item.code == cellValue).name
    } else {
        return ''
    }


}
const formatUnitId = (cellValue) => {
    if (props.zcgsdwList.length && cellValue) {
        return props.zcgsdwList.find(item => item.codeColumn == cellValue).valueColumn
    } else {
        return ''
    }


}


const formateduLevelId = (cellValue) => {
    if (props.xlList.length && cellValue) {
        return props.xlList.find(item => item.code == cellValue).name
    } else {
        return ''
    }


}

const getRuleForm = (i, j) => {
    if (i.honorApplyBookMemberVOs && i.honorApplyBookMemberVOs.length > 0) {
        tableData.length = 0; // 清空数组
        tableData.push(...i.honorApplyBookMemberVOs); // 添加新元素

    }
    for (const key in i) {
        ruleForm[key] = i[key];
    }
    procInsId.value = j;
    checker.value = ruleForm.checker;
    checkDate.value = ruleForm.checkdate;
}
const { proxy } = getCurrentInstance();
const downloadMet = (i) => {
    proxy.$download.common(i)
}
defineExpose({
    getRuleForm
})
</script>
<style lang="scss">
.gdlable {
    width: 140px;
}
</style>
<style scoped lang="scss">
@import url("@/views/achievement/index.scss");

:deep(.el-select--default) {


    .el-select__wrapper.is-disabled {
        background-color: #fff;
        box-shadow: 0 0 0 0px var(--el-select-disabled-border) inset;
        color: #606266;
        cursor: not-allowed;

        .el-select__selected-item {
            color: #606266;
        }
    }

    .el-select__suffix {
        display: none;
    }
}
</style>
